package jcpcotizaciones.vista;

import java.awt.Cursor;
import java.sql.SQLException;
import java.text.DecimalFormat;
import java.util.Iterator;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.table.DefaultTableModel;
import jcpcotizaciones.Control.ControlCliente;
import jcpcotizaciones.Modelo.Cliente;
import javax.swing.JOptionPane;

public class vistaCliente extends javax.swing.JFrame {
    DefaultTableModel dtm = new DefaultTableModel();
    public vistaCliente(){
        initComponents();
        listarClientes();

    }

    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jd_eliminar = new javax.swing.JDialog();
        jPanel1 = new javax.swing.JPanel();
        Aceptar_eliminar = new javax.swing.JButton();
        Cancelar_Eliminar = new javax.swing.JButton();
        jLabel9 = new javax.swing.JLabel();
        jcMousePanel4 = new jcMousePanel.jcMousePanel();
        pisoCliente = new jcMousePanel.jcMousePanel();
        gestion = new jcMousePanel.jcMousePanel();
        jLabel1 = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        tx_codigo = new javax.swing.JTextField();
        tx_cedula = new javax.swing.JTextField();
        tx_nombre = new javax.swing.JTextField();
        tx_direccion = new javax.swing.JTextField();
        tx_telefono = new javax.swing.JTextField();
        tx_email = new javax.swing.JTextField();
        jcMousePanel1 = new jcMousePanel.jcMousePanel();
        bt_agregar = new javax.swing.JButton();
        bt_modificar = new javax.swing.JButton();
        bt_eliminar = new javax.swing.JButton();
        bt_limpiar = new javax.swing.JButton();
        jcMousePanel2 = new jcMousePanel.jcMousePanel();
        scrollTabla = new javax.swing.JScrollPane();
        tablaClientes = new javax.swing.JTable(dtm);
        jcMousePanel3 = new jcMousePanel.jcMousePanel();
        cb_buscar = new javax.swing.JComboBox();
        tx_buscar = new javax.swing.JTextField();
        bt_buscar = new javax.swing.JButton();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(jcpcotizaciones.JCPCOTIZACIONESApp.class).getContext().getResourceMap(vistaCliente.class);
        jd_eliminar.setTitle(resourceMap.getString("jd_eliminar.title")); // NOI18N
        jd_eliminar.setModal(true);
        jd_eliminar.setName("jd_eliminar"); // NOI18N

        jPanel1.setName("jPanel1"); // NOI18N

        Aceptar_eliminar.setText(resourceMap.getString("Aceptar_eliminar.text")); // NOI18N
        Aceptar_eliminar.setName("Aceptar_eliminar"); // NOI18N
        Aceptar_eliminar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Aceptar_eliminarActionPerformed(evt);
            }
        });

        Cancelar_Eliminar.setText(resourceMap.getString("Cancelar_Eliminar.text")); // NOI18N
        Cancelar_Eliminar.setName("Cancelar_Eliminar"); // NOI18N
        Cancelar_Eliminar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                Cancelar_EliminarActionPerformed(evt);
            }
        });

        jLabel9.setText(resourceMap.getString("jLabel9.text")); // NOI18N
        jLabel9.setName("jLabel9"); // NOI18N

        jcMousePanel4.setIcon(resourceMap.getIcon("jcMousePanel4.icon")); // NOI18N
        jcMousePanel4.setName("jcMousePanel4"); // NOI18N

        javax.swing.GroupLayout jcMousePanel4Layout = new javax.swing.GroupLayout(jcMousePanel4);
        jcMousePanel4.setLayout(jcMousePanel4Layout);
        jcMousePanel4Layout.setHorizontalGroup(
            jcMousePanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 59, Short.MAX_VALUE)
        );
        jcMousePanel4Layout.setVerticalGroup(
            jcMousePanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 54, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jcMousePanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(75, 75, 75)
                .addComponent(jLabel9, javax.swing.GroupLayout.PREFERRED_SIZE, 197, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap(152, Short.MAX_VALUE)
                .addComponent(Aceptar_eliminar)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(Cancelar_Eliminar)
                .addGap(47, 47, 47))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGap(21, 21, 21)
                        .addComponent(jLabel9))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(jcMousePanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 32, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(Aceptar_eliminar)
                    .addComponent(Cancelar_Eliminar))
                .addContainerGap())
        );

        javax.swing.GroupLayout jd_eliminarLayout = new javax.swing.GroupLayout(jd_eliminar.getContentPane());
        jd_eliminar.getContentPane().setLayout(jd_eliminarLayout);
        jd_eliminarLayout.setHorizontalGroup(
            jd_eliminarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
        );
        jd_eliminarLayout.setVerticalGroup(
            jd_eliminarLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setName("Form"); // NOI18N

        pisoCliente.setFocusable(false);
        pisoCliente.setIcon(new javax.swing.ImageIcon(getClass().getResource("/jcpcotizaciones/resources/Ventanas/windows.jpg"))); // NOI18N
        pisoCliente.setName("pisoCliente"); // NOI18N

        gestion.setBorder(javax.swing.BorderFactory.createTitledBorder(null, resourceMap.getString("gestion.border.title"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, resourceMap.getFont("gestion.border.titleFont"), resourceMap.getColor("gestion.border.titleColor"))); // NOI18N
        gestion.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        gestion.setIcon(resourceMap.getIcon("gestion.icon")); // NOI18N
        gestion.setName("gestion"); // NOI18N

        jLabel1.setText(resourceMap.getString("jLabel1.text")); // NOI18N
        jLabel1.setName("jLabel1"); // NOI18N

        jLabel2.setText(resourceMap.getString("jLabel2.text")); // NOI18N
        jLabel2.setName("jLabel2"); // NOI18N

        jLabel3.setText(resourceMap.getString("jLabel3.text")); // NOI18N
        jLabel3.setName("jLabel3"); // NOI18N

        jLabel4.setText(resourceMap.getString("jLabel4.text")); // NOI18N
        jLabel4.setName("jLabel4"); // NOI18N

        jLabel5.setText(resourceMap.getString("jLabel5.text")); // NOI18N
        jLabel5.setName("jLabel5"); // NOI18N

        jLabel6.setText(resourceMap.getString("jLabel6.text")); // NOI18N
        jLabel6.setName("jLabel6"); // NOI18N

        tx_codigo.setFont(resourceMap.getFont("tx_codigo.font")); // NOI18N
        tx_codigo.setText(resourceMap.getString("tx_codigo.text")); // NOI18N
        tx_codigo.setEnabled(false);
        tx_codigo.setName("tx_codigo"); // NOI18N

        tx_cedula.setText(resourceMap.getString("tx_cedula.text")); // NOI18N
        tx_cedula.setName("tx_cedula"); // NOI18N
        tx_cedula.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tx_cedulaActionPerformed(evt);
            }
        });
        tx_cedula.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                tx_cedulaFocusLost(evt);
            }
        });

        tx_nombre.setText(resourceMap.getString("tx_nombre.text")); // NOI18N
        tx_nombre.setName("tx_nombre"); // NOI18N
        tx_nombre.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                tx_nombreFocusLost(evt);
            }
        });

        tx_direccion.setHorizontalAlignment(javax.swing.JTextField.LEFT);
        tx_direccion.setText(resourceMap.getString("tx_direccion.text")); // NOI18N
        tx_direccion.setName("tx_direccion"); // NOI18N
        tx_direccion.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                tx_direccionFocusLost(evt);
            }
        });

        tx_telefono.setText(resourceMap.getString("tx_telefono.text")); // NOI18N
        tx_telefono.setName("tx_telefono"); // NOI18N
        tx_telefono.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                tx_telefonoFocusLost(evt);
            }
        });

        tx_email.setText(resourceMap.getString("tx_email.text")); // NOI18N
        tx_email.setName("tx_email"); // NOI18N
        tx_email.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tx_emailActionPerformed(evt);
            }
        });
        tx_email.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                tx_emailFocusLost(evt);
            }
        });

        javax.swing.GroupLayout gestionLayout = new javax.swing.GroupLayout(gestion);
        gestion.setLayout(gestionLayout);
        gestionLayout.setHorizontalGroup(
            gestionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(gestionLayout.createSequentialGroup()
                .addGroup(gestionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel4)
                    .addComponent(jLabel1)
                    .addComponent(jLabel2)
                    .addComponent(jLabel3)
                    .addComponent(jLabel6)
                    .addComponent(jLabel5))
                .addGap(18, 18, 18)
                .addGroup(gestionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addComponent(tx_email)
                    .addComponent(tx_telefono)
                    .addComponent(tx_direccion)
                    .addComponent(tx_nombre)
                    .addComponent(tx_cedula)
                    .addComponent(tx_codigo, javax.swing.GroupLayout.PREFERRED_SIZE, 161, javax.swing.GroupLayout.PREFERRED_SIZE)))
        );
        gestionLayout.setVerticalGroup(
            gestionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(gestionLayout.createSequentialGroup()
                .addGroup(gestionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel1)
                    .addComponent(tx_codigo, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(gestionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel2)
                    .addComponent(tx_cedula, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(gestionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel3)
                    .addComponent(tx_nombre, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(8, 8, 8)
                .addGroup(gestionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel4)
                    .addComponent(tx_direccion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(gestionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel5)
                    .addComponent(tx_telefono, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(gestionLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(jLabel6)
                    .addComponent(tx_email, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
        );

        jcMousePanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, resourceMap.getString("jcMousePanel1.border.title"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, resourceMap.getFont("jcMousePanel1.border.titleFont"), resourceMap.getColor("jcMousePanel1.border.titleColor"))); // NOI18N
        jcMousePanel1.setIcon(resourceMap.getIcon("jcMousePanel1.icon")); // NOI18N
        jcMousePanel1.setName("jcMousePanel1"); // NOI18N

        bt_agregar.setFont(resourceMap.getFont("bt_agregar.font")); // NOI18N
        bt_agregar.setIcon(resourceMap.getIcon("bt_agregar.icon")); // NOI18N
        bt_agregar.setText(resourceMap.getString("bt_agregar.text")); // NOI18N
        bt_agregar.setName("bt_agregar"); // NOI18N
        bt_agregar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_agregarActionPerformed(evt);
            }
        });

        bt_modificar.setFont(resourceMap.getFont("bt_modificar.font")); // NOI18N
        bt_modificar.setIcon(resourceMap.getIcon("bt_modificar.icon")); // NOI18N
        bt_modificar.setText(resourceMap.getString("bt_modificar.text")); // NOI18N
        bt_modificar.setEnabled(false);
        bt_modificar.setName("bt_modificar"); // NOI18N
        bt_modificar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_modificarActionPerformed(evt);
            }
        });

        bt_eliminar.setFont(resourceMap.getFont("bt_eliminar.font")); // NOI18N
        bt_eliminar.setIcon(resourceMap.getIcon("bt_eliminar.icon")); // NOI18N
        bt_eliminar.setText(resourceMap.getString("bt_eliminar.text")); // NOI18N
        bt_eliminar.setEnabled(false);
        bt_eliminar.setName("bt_eliminar"); // NOI18N
        bt_eliminar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_eliminarActionPerformed(evt);
            }
        });

        bt_limpiar.setFont(resourceMap.getFont("bt_limpiar.font")); // NOI18N
        bt_limpiar.setIcon(resourceMap.getIcon("bt_limpiar.icon")); // NOI18N
        bt_limpiar.setText(resourceMap.getString("bt_limpiar.text")); // NOI18N
        bt_limpiar.setName("bt_limpiar"); // NOI18N
        bt_limpiar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_limpiarActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jcMousePanel1Layout = new javax.swing.GroupLayout(jcMousePanel1);
        jcMousePanel1.setLayout(jcMousePanel1Layout);
        jcMousePanel1Layout.setHorizontalGroup(
            jcMousePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jcMousePanel1Layout.createSequentialGroup()
                .addGroup(jcMousePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
                    .addComponent(bt_modificar, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(bt_agregar, javax.swing.GroupLayout.DEFAULT_SIZE, 99, Short.MAX_VALUE)
                    .addComponent(bt_eliminar, javax.swing.GroupLayout.DEFAULT_SIZE, 99, Short.MAX_VALUE)
                    .addComponent(bt_limpiar, javax.swing.GroupLayout.DEFAULT_SIZE, 99, Short.MAX_VALUE))
                .addGap(10, 10, 10))
        );
        jcMousePanel1Layout.setVerticalGroup(
            jcMousePanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jcMousePanel1Layout.createSequentialGroup()
                .addComponent(bt_agregar, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(bt_modificar)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(bt_eliminar)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(bt_limpiar)
                .addContainerGap(47, Short.MAX_VALUE))
        );

        jcMousePanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, resourceMap.getString("jcMousePanel2.border.title"), javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, resourceMap.getFont("jcMousePanel2.border.titleFont"), resourceMap.getColor("jcMousePanel2.border.titleColor"))); // NOI18N
        jcMousePanel2.setIcon(resourceMap.getIcon("jcMousePanel2.icon")); // NOI18N
        jcMousePanel2.setName("jcMousePanel2"); // NOI18N

        scrollTabla.setName("scrollTabla"); // NOI18N

        dtm.addColumn("Código");
        dtm.addColumn("Cédula");
        dtm.addColumn("Nombre");
        dtm.addColumn("Dirección");
        dtm.addColumn("Teléfono");
        dtm.addColumn("e-mail");
        tablaClientes.setAutoCreateRowSorter(true);
        tablaClientes.setAlignmentX(1.0F);
        tablaClientes.setAlignmentY(1.0F);
        tablaClientes.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF);
        tablaClientes.setAutoscrolls(false);
        tablaClientes.setCellSelectionEnabled(true);
        tablaClientes.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        tablaClientes.setDragEnabled(true);
        tablaClientes.setEnabled(false);
        tablaClientes.setName("tablaClientes"); // NOI18N
        tablaClientes.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        tablaClientes.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                tablaClientesMouseEntered(evt);
            }
        });
        scrollTabla.setViewportView(tablaClientes);
        tablaClientes.getColumnModel().getSelectionModel().setSelectionMode(javax.swing.ListSelectionModel.SINGLE_INTERVAL_SELECTION);

        javax.swing.GroupLayout jcMousePanel2Layout = new javax.swing.GroupLayout(jcMousePanel2);
        jcMousePanel2.setLayout(jcMousePanel2Layout);
        jcMousePanel2Layout.setHorizontalGroup(
            jcMousePanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(scrollTabla, javax.swing.GroupLayout.DEFAULT_SIZE, 433, Short.MAX_VALUE)
        );
        jcMousePanel2Layout.setVerticalGroup(
            jcMousePanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(scrollTabla, javax.swing.GroupLayout.DEFAULT_SIZE, 257, Short.MAX_VALUE)
        );

        jcMousePanel3.setIcon(resourceMap.getIcon("jcMousePanel3.icon")); // NOI18N
        jcMousePanel3.setName("jcMousePanel3"); // NOI18N

        javax.swing.GroupLayout jcMousePanel3Layout = new javax.swing.GroupLayout(jcMousePanel3);
        jcMousePanel3.setLayout(jcMousePanel3Layout);
        jcMousePanel3Layout.setHorizontalGroup(
            jcMousePanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 353, Short.MAX_VALUE)
        );
        jcMousePanel3Layout.setVerticalGroup(
            jcMousePanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 42, Short.MAX_VALUE)
        );

        cb_buscar.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Código", "Cédula", "Nombre" }));
        cb_buscar.setName("cb_buscar"); // NOI18N

        tx_buscar.setText(resourceMap.getString("tx_buscar.text")); // NOI18N
        tx_buscar.setName("tx_buscar"); // NOI18N
        tx_buscar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                tx_buscarActionPerformed(evt);
            }
        });
        tx_buscar.addFocusListener(new java.awt.event.FocusAdapter() {
            public void focusLost(java.awt.event.FocusEvent evt) {
                tx_buscarFocusLost(evt);
            }
        });
        tx_buscar.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                tx_buscarKeyPressed(evt);
            }
        });

        bt_buscar.setIcon(resourceMap.getIcon("bt_buscar.icon")); // NOI18N
        bt_buscar.setText(resourceMap.getString("bt_buscar.text")); // NOI18N
        bt_buscar.setName("bt_buscar"); // NOI18N
        bt_buscar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                bt_buscarActionPerformed(evt);
            }
        });
        bt_buscar.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                bt_buscarKeyPressed(evt);
            }
        });

        jLabel7.setText(resourceMap.getString("jLabel7.text")); // NOI18N
        jLabel7.setName("jLabel7"); // NOI18N

        jLabel8.setText(resourceMap.getString("jLabel8.text")); // NOI18N
        jLabel8.setName("jLabel8"); // NOI18N

        javax.swing.GroupLayout pisoClienteLayout = new javax.swing.GroupLayout(pisoCliente);
        pisoCliente.setLayout(pisoClienteLayout);
        pisoClienteLayout.setHorizontalGroup(
            pisoClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pisoClienteLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(pisoClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(pisoClienteLayout.createSequentialGroup()
                        .addGap(236, 236, 236)
                        .addComponent(jcMousePanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(pisoClienteLayout.createSequentialGroup()
                        .addGroup(pisoClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel7)
                            .addComponent(cb_buscar, javax.swing.GroupLayout.PREFERRED_SIZE, 107, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(pisoClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(tx_buscar, javax.swing.GroupLayout.PREFERRED_SIZE, 254, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLabel8))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jcMousePanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(pisoClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                        .addComponent(bt_buscar)
                        .addGroup(pisoClienteLayout.createSequentialGroup()
                            .addComponent(gestion, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                            .addComponent(jcMousePanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(19, Short.MAX_VALUE))
        );
        pisoClienteLayout.setVerticalGroup(
            pisoClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(pisoClienteLayout.createSequentialGroup()
                .addGap(22, 22, 22)
                .addComponent(jcMousePanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(29, 29, 29)
                .addGroup(pisoClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(pisoClienteLayout.createSequentialGroup()
                        .addGroup(pisoClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLabel7)
                            .addComponent(jLabel8))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(pisoClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(cb_buscar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(tx_buscar, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(bt_buscar)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(pisoClienteLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                            .addComponent(jcMousePanel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addComponent(gestion, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addComponent(jcMousePanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(34, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(pisoCliente, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(pisoCliente, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
   
    private void tx_cedulaActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tx_cedulaActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_tx_cedulaActionPerformed

    private void tx_emailActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tx_emailActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_tx_emailActionPerformed

    private void bt_limpiarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_limpiarActionPerformed
        limpiar();
        listarClientes();
    }//GEN-LAST:event_bt_limpiarActionPerformed

    private void bt_agregarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_agregarActionPerformed
        guardar();
    }//GEN-LAST:event_bt_agregarActionPerformed

    private void bt_buscarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_buscarActionPerformed
        buscar();
    }//GEN-LAST:event_bt_buscarActionPerformed

    private void tx_buscarFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_tx_buscarFocusLost
       
    }//GEN-LAST:event_tx_buscarFocusLost

    private void bt_modificarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_modificarActionPerformed
        modificar();
    }//GEN-LAST:event_bt_modificarActionPerformed

    private void bt_eliminarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bt_eliminarActionPerformed
            jd_eliminar.setSize(350, 150);
            jd_eliminar.setLocation(350, 300);
            jd_eliminar.setVisible(true);
    }//GEN-LAST:event_bt_eliminarActionPerformed

    private void tablaClientesMouseEntered(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_tablaClientesMouseEntered
        tablaClientes.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
}//GEN-LAST:event_tablaClientesMouseEntered

    private void Aceptar_eliminarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Aceptar_eliminarActionPerformed
      
      try {
            ControlCliente.EliminarCliente(tx_codigo.getText());
            limpiar();
            listarClientes();
        } catch (SQLException ex) {
            Logger.getLogger(vistaCliente.class.getName()).log(Level.SEVERE, null, ex);
        } catch (Exception ex) {
            Logger.getLogger(vistaCliente.class.getName()).log(Level.SEVERE, null, ex);
        }
      jd_eliminar.setVisible(false);
      JOptionPane.showMessageDialog(null,"Cliente eliminado con exito!");
    }//GEN-LAST:event_Aceptar_eliminarActionPerformed

    private void Cancelar_EliminarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_Cancelar_EliminarActionPerformed
        jd_eliminar.setVisible(false);
    }//GEN-LAST:event_Cancelar_EliminarActionPerformed

    private void tx_buscarKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_tx_buscarKeyPressed

    }//GEN-LAST:event_tx_buscarKeyPressed

    private void tx_cedulaFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_tx_cedulaFocusLost

    }//GEN-LAST:event_tx_cedulaFocusLost

    private void tx_nombreFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_tx_nombreFocusLost
        tx_nombre.setText(ControlValidacion.convertirMayuscula(tx_nombre.getText()));
    }//GEN-LAST:event_tx_nombreFocusLost

    private void tx_direccionFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_tx_direccionFocusLost
        tx_direccion.setText(ControlValidacion.convertirMayuscula(tx_direccion.getText()));
    }//GEN-LAST:event_tx_direccionFocusLost

    private void tx_telefonoFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_tx_telefonoFocusLost

    }//GEN-LAST:event_tx_telefonoFocusLost

    private void tx_emailFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_tx_emailFocusLost

    }//GEN-LAST:event_tx_emailFocusLost

    private void bt_buscarKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_bt_buscarKeyPressed
        // TODO add your handling code here:
    }//GEN-LAST:event_bt_buscarKeyPressed

    private void tx_buscarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_tx_buscarActionPerformed
        this.buscar();
    }//GEN-LAST:event_tx_buscarActionPerformed

public void listarClientes(){ // Muestra todos los clientes que estan registrados hasta el momento.
        Cliente cli = new Cliente();
        try {
            dtm.setNumRows(0);
            ControlCliente.listarClientes();
            Iterator it = ControlCliente.getCliente().iterator();
                while (it.hasNext()) {
                    cli = (Cliente) it.next();
                    String[] fila = {cli.getCodigo(), cli.getCedula(), cli.getNombre(), cli.getDireccion(), cli.getTelefono(),cli.getEmail()};
                    dtm.addRow(fila);
                }
            DecimalFormat formateador = new DecimalFormat("000");
            if(cli.getCodigo()==null){
                tx_codigo.setText(formateador.format(1));
            }else{
                int contador_cliente =Integer.parseInt(cli.getCodigo());
                contador_cliente+=1;
                tx_codigo.setText(formateador.format(contador_cliente));
            }
        } catch (SQLException ex) {
            Logger.getLogger(vistaCliente.class.getName()).log(Level.SEVERE, null, ex);
        } catch (Exception ex) {
            Logger.getLogger(vistaCliente.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

public void modificar(){ // después de buscar el cliente, llena todos los campos de los datos del mismo para que el usuario pueda escoger el 
                         // campo o los campos que va ha modificar y luego guardarlos en la base de datos.
    try {
            if (tx_cedula.getText().trim().equals("")||tx_nombre.getText().trim().equals("")||tx_nombre.getText().trim().equals("")||tx_direccion.getText().trim().equals("")|| tx_telefono.getText().trim().equals("") || tx_email.getText().trim().equals("")){
                JOptionPane.showMessageDialog(null,"Asegurese de llenar todos los campos");
            }
            boolean e = ControlValidacion.validaEmail(tx_email);
            boolean t = ControlValidacion.validaNumero(tx_telefono, 11);
            boolean c = ControlValidacion.validaNumero(tx_cedula, 45);
            if(e && t && c){
                Cliente cli = new Cliente();
                cli.setCodigo(tx_codigo.getText());
                cli.setCedula(tx_cedula.getText());
                cli.setNombre(tx_nombre.getText());
                cli.setDireccion(tx_direccion.getText());
                cli.setTelefono(tx_telefono.getText());
                cli.setEmail(tx_email.getText());
                ControlCliente.ModificarCliente(cli,tx_codigo.getText());
                limpiar();
                listarClientes();
                JOptionPane.showMessageDialog(null,"Cliente modificado con exito!.");
            }else{
                e = ControlValidacion.validaEmail(tx_email);
                t = ControlValidacion.validaNumero(tx_telefono, 11);
                c = ControlValidacion.validaNumero(tx_cedula, 15);
                JOptionPane.showMessageDialog(null,"digite bien los datos");
            }
        } catch (SQLException ex) {
            Logger.getLogger(vistaCliente.class.getName()).log(Level.SEVERE, null, ex);
        } catch (Exception ex) {
            Logger.getLogger(vistaCliente.class.getName()).log(Level.SEVERE, null, ex);
        }
}

public void guardar(){ // guarda un nuevo cliente en la base de datos.
    try {

                if (tx_cedula.getText().trim().equals("")||tx_nombre.getText().trim().equals("")||tx_nombre.getText().trim().equals("")||tx_direccion.getText().trim().equals("")|| tx_telefono.getText().trim().equals("") || tx_email.getText().trim().equals("")){
                    JOptionPane.showMessageDialog(null,"Asegurese de llenar odos los campos");
                }
                boolean e = ControlValidacion.validaEmail(tx_email);
                boolean t = ControlValidacion.validaNumero(tx_telefono, 11);
                boolean c = ControlValidacion.validaNumero(tx_cedula, 45);

                if(e && t && c){
                    Cliente cli = new Cliente();
                    cli.setCodigo(tx_codigo.getText());
                    cli.setCedula(tx_cedula.getText());
                    cli.setNombre(tx_nombre.getText());
                    cli.setDireccion(tx_direccion.getText());
                    cli.setTelefono(tx_telefono.getText());
                    cli.setEmail(tx_email.getText());
                    ControlCliente.agregarClientes(cli);
                    limpiar();
                    listarClientes();
                    JOptionPane.showMessageDialog(null,"Cliente guardado con exito!.");
                }else{
                    e = ControlValidacion.validaEmail(tx_email);
                    t = ControlValidacion.validaNumero(tx_telefono, 11);
                    c = ControlValidacion.validaNumero(tx_cedula, 45);
                    JOptionPane.showMessageDialog(null,"digite bien los datos");
                }

        } catch (SQLException ex) {
            Logger.getLogger(vistaCliente.class.getName()).log(Level.SEVERE, null, ex);
        } catch (Exception ex) {
            Logger.getLogger(vistaCliente.class.getName()).log(Level.SEVERE, null, ex);
        }
}

public void limpiar(){ // borra todos los campos de texto del formulario.
        
        tx_cedula.setText("");
        tx_nombre.setText("");
        tx_direccion.setText("");
        tx_telefono.setText("");
        tx_email.setText("");
        cb_buscar.setSelectedIndex(0);
        bt_modificar.setEnabled(false);
        bt_eliminar.setEnabled(false);
        bt_agregar.setEnabled(true);
    }

public void buscar(){ // busca el cliente por medio de su código, nombre o cédula.
        String item = cb_buscar.getSelectedItem().toString();
        Cliente cli;
        try {
            if(tx_buscar.getText().trim().equals("")){
                JOptionPane.showMessageDialog(null,"Por favor digite un criterio de busqueda.");
            }else{
                if(item.equals("Código")){
                 cli = ControlCliente.BuscarCliente(tx_buscar.getText());
                }else{
                    if(item.equals("Cédula")){
                    cli = ControlCliente.BuscarClienteCed(tx_buscar.getText());
                    }else{
                        cli = ControlCliente.BuscarClienteNom(tx_buscar.getText());
                    }
                }
                if(cli != null){
                    tx_codigo.setText(cli.getCodigo());
                    tx_cedula.setText(cli.getCedula());
                    tx_nombre.setText(cli.getNombre());
                    tx_direccion.setText(cli.getDireccion());
                    tx_telefono.setText(cli.getTelefono());
                    tx_email.setText(cli.getEmail());
                    bt_modificar.setEnabled(true);
                    bt_eliminar.setEnabled(true);
                    bt_agregar.setEnabled(false);
                    tx_buscar.setText("");
                }else{
                    JOptionPane.showMessageDialog(null,"Cliente no encontrado.");
                }
            }
            } catch (SQLException ex) {
                Logger.getLogger(vistaCliente.class.getName()).log(Level.SEVERE, null, ex);
            }
    }

public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {
            public void run() {
            }
        });
}

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton Aceptar_eliminar;
    private javax.swing.JButton Cancelar_Eliminar;
    private javax.swing.JButton bt_agregar;
    private javax.swing.JButton bt_buscar;
    private javax.swing.JButton bt_eliminar;
    private javax.swing.JButton bt_limpiar;
    private javax.swing.JButton bt_modificar;
    private javax.swing.JComboBox cb_buscar;
    private jcMousePanel.jcMousePanel gestion;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JPanel jPanel1;
    private jcMousePanel.jcMousePanel jcMousePanel1;
    private jcMousePanel.jcMousePanel jcMousePanel2;
    private jcMousePanel.jcMousePanel jcMousePanel3;
    private jcMousePanel.jcMousePanel jcMousePanel4;
    private javax.swing.JDialog jd_eliminar;
    public static jcMousePanel.jcMousePanel pisoCliente;
    private javax.swing.JScrollPane scrollTabla;
    private javax.swing.JTable tablaClientes;
    private javax.swing.JTextField tx_buscar;
    private javax.swing.JTextField tx_cedula;
    private javax.swing.JTextField tx_codigo;
    private javax.swing.JTextField tx_direccion;
    private javax.swing.JTextField tx_email;
    private javax.swing.JTextField tx_nombre;
    private javax.swing.JTextField tx_telefono;
    // End of variables declaration//GEN-END:variables

}
